/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package loja.gui.tablemodel;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import loja.dominio.Marca;

/**
 *
 * @author Rodrigo
 */
public class MarcaTableModel extends AbstractTableModel {

    private List<Marca> CadMarcas;
    private static final String[] COLUNAS = {"Codigo", "Marca"};

    public MarcaTableModel() {
        CadMarcas = new ArrayList<Marca>();
    }

    public void setCadMarcas(List<Marca> cadMarcas) {
        this.CadMarcas = cadMarcas;
        fireTableDataChanged();
    }

    public void addCadMarcas(Marca marca) {
        this.CadMarcas.add(marca);
        fireTableDataChanged();
    }

    public void limpar() {
        this.CadMarcas = new ArrayList<Marca>();
        fireTableDataChanged();
    }

    public Marca getMarca(int rowIndex) {
        return CadMarcas.get(rowIndex);
    }

    public int getRowCount() {
        return CadMarcas.size();
    }

    public int getColumnCount() {
        return COLUNAS.length;
    }

    @Override
    public String getColumnName(int column) {
        return COLUNAS[column];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Marca m = CadMarcas.get(rowIndex);

        switch (columnIndex) {
            case 0:
                return m.getId();
            case 1:
                return m.getMarca();
            default:
                return "Valor Desconhecido";
        }
    }
}
